<script>
import {update} from '@/api/device'
export default {
    props:{
        show: {
            type: Boolean,
            defalut: false
        },
        item: {
            type: Object,
            default: ()=>{}
        }
    },
    watch:{
        show: {
            handler(nv) {
                if(nv) {
                    this.form = this.item||{}
                }
            },
            immediate: true
        }
    },
    data() {
        return {
            form: {},
            rules: {
                name: {required: true, message: '请输入名称', trigger: 'blur'}
            }
        }
    },
    methods: {
        close() {
            this.$emit('update:show', false)
        },
        submit() {
            this.$refs['form'].validate(valid => {
                if(valid) {
                    update(this.form).then(res => {
                        if(res.code == 1) {
                            this.$emit('confirm');
                            this.close()
                        }
                    })
                }
            })
        }
    }
}
</script>

<template>
    <el-dialog title="修改" :visible="show" :before-close="close" top="15vh">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="名称" prop="name">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="编码">
                <el-input v-model="form.code" disabled></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </div>
    </el-dialog>
</template>

<style scoped lang="scss">

</style>

